<template>
  <div class="modal fade"
       id="editCusModal"
       tabindex="-1"
       role="dialog"
       aria-labelledby="myModalLabel"
       aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <!-- <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button> -->
          <h4 class="modal-title"
              id="myModalLabel">编辑客户</h4>
        </div>
        <div class="modal-body">
          <div class="form-horizontal">
            <div class="form-group">
              <label class="col-md-3 col-sm-2 control-label">客户姓名：</label>
              <div class="col-md-8 col-sm-10">
                <input type="text"
                       class="form-control"
                       placeholder="请填写客户姓名"
                       v-model="customerInfo.name">
              </div>
            </div>
            <div class="form-group">
              <label class="col-md-3 col-sm-2 control-label">客户性别：</label>
              <div class="col-md-8 col-sm-10">
                <label class="radio-inline">
                  <input type="radio"
                         name="inlineRadioOptions"
                         id="inlineRadio2"
                         value="0"
                         v-model="customerInfo.gender"> 先生
                </label>
                <label class="radio-inline">
                  <input type="radio"
                         name="inlineRadioOptions"
                         id="inlineRadio3"
                         value="1"
                         v-model="customerInfo.gender"> 女士
                </label>
              </div>
            </div>
            <div class="form-group">
              <label for=""
                     class="col-sm-3 control-label">客户意向：</label>
              <div class="col-sm-8">
                <textarea rows="5"
                          class="form-control"
                          placeholder="客户意向"
                          v-model="customerInfo.remark"></textarea>
              </div>
            </div>
          </div>
        </div>
        <div class="modal-footer">
          <button type="button"
                  class="btn checkedBtn"
                  v-show="btnShow"
                  @click="saveCusInfo">确定</button>
          <button type="button"
                  class="btn btn-default"
                  v-show="btnShow"
                  @click="canel">取消</button>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  //接收父组件的绑定值
  props: ["customerInfo"],
  data() {
    return {
      btnShow: true,
    };
  },
  watch: {
    customerInfo: {
      handler(curVal, oldVal) {
        this.customerInfo = curVal;
      },
      deep: true,
    },
  },
  mounted() {},
  methods: {
    saveCusInfo() {
      let _self = this;

      if (!_self.customerInfo.cpId) {
        layer.msg("客户标识不能为空！");
        return;
      }
      if (!_self.customerInfo.name) {
        layer.msg("客户姓名不能为空！");
        return;
      }
      if (!_self.customerInfo.gender) {
        layer.msg("请选择客户性别！");
        return;
      }

      let url = this.utilHelper.apiUrl + "/api/editCustomerInfo";
      let body = {};
      body.params = _self.customerInfo;
      _self.$http.post(url, body).then(
        (response) => {
          let res = response.body.resData;
          if (res.result == "1") {
            layer.msg("编辑成功");
            this.canel();
            _self.$emit("editCusListener");
          } else {
            layer.msg("编辑失败");
          }
        },
        (response) => {
          layer.msg("编辑失败");
        }
      );
    },
    canel() {
      $("#editCusModal").modal("hide");
    },
  },
};
</script>